package com.jiejie.university.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.jiejie.university.entity.Manage;
import com.jiejie.university.mapper.ManageMapper;
import com.jiejie.university.service.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ManageServiceImpl implements ManageService {
    @Autowired
    private ManageMapper manageMapper;

    @Override
    public Manage login(String username, String password) {
        return manageMapper.login(username,password);
    }

    /**
     * 根据用户名查找
     * @param username
     * @return
     */
    @Override
    public Manage findUsername(String username) {
        return manageMapper.findByUsername(username);
    }

    @Override
    @Transactional
    public int register(Manage manage) {
        Manage info = findUsername(manage.getUsername());
        if (BeanUtil.isEmpty(info)) {
            int i = manageMapper.register(manage);
            if (i > 0)
                return 200;
            else
                return 0;
        } else {
            return 0;
        }

    }
}
